<template>
  <div class='login-panel'>
    <h1 class='title'>龙王管理系统</h1>
    <!-- 中间tabs切换 -->
    <div class='tabs'>
      <el-tabs type='border-card' stretch v-model='activeName'>
        <el-tab-pane label='account' name='account'>
          <template #label>
            <div class='label'>
              <el-icon>
                <UserFilled />
              </el-icon>
              <span class='text'>账号登录</span>
            </div>
          </template>
          <pane-account ref='accountRef' />
        </el-tab-pane>

        <el-tab-pane label='phone' name='phone'>
          <template #label>
            <div class='label'>
              <el-icon>
                <Cellphone />
              </el-icon>
              <span class='text'>手机登录</span>
            </div>
          </template>
          <div>当前为手机号登录页面</div>
        </el-tab-pane>
        <pane-phone />
      </el-tabs>
    </div>
    <div class='controls'>
      <el-checkbox v-model='isRemPwd' label='记住密码' size='large' />
      <el-link type='primary'>忘记密码</el-link>
    </div>
    <el-button class='login-btn' type='primary' size='large' @click='handleLoginBtnClick'>立即登录</el-button>
  </div>
</template>


<script setup lang='ts'>
import PaneAccount from '@/views/login/c-cpns/Pane-account.vue'
import PanePhone from '@/views/login/c-cpns/Pane-phone.vue'
import { ref, watch } from 'vue'
import { Cellphone, UserFilled } from '@element-plus/icons-vue'
import { localCache } from '@/utils/cache'

const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)

watch(isRemPwd, (newValue) => {
  localCache.setCache('isRemPwd', newValue)
})
const activeName = ref('account')
const accountRef = ref<InstanceType<typeof PaneAccount>>()

function handleLoginBtnClick() {
  if (activeName.value === 'account') {
    // 当前为账号登录
    accountRef.value.loginAction(isRemPwd.value)
  } else {
    // 反之则为手机号登录
  }
}
</script>


<style lang='less' scoped>
.login-panel {
  width: 330px;
  margin-bottom: 150px;

  .title {
    text-align: center;
    margin-bottom: 15px;
  }

  .label {
    display: flex;
    align-items: center;
    justify-content: center;

    .text {
      margin-left: 5px;
    }
  }

  .controls {
    margin-top: 12px;
    display: flex;

    justify-content: space-between;
  }

  .login-btn {
    margin-top: 10px;
    width: 100%;
    // --el-button-size: 50px;
  }
}
</style>
